package com.ruoyi.biz.organization.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.biz.organization.domain.BizCompany;
import com.ruoyi.biz.organization.service.IBizCompanyService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 项目信息Controller
 *
 * @author Fei.Cong
 * @date 2023-04-21
 */
@RestController
@RequestMapping("/organization/company")
public class BizCompanyController extends BaseController {

    @Autowired
    private IBizCompanyService bizCompanyService;

    /**
     * 查询项目信息列表
     */
    @PreAuthorize("@ss.hasPermi('crane:company:list')")
    @GetMapping("/list")
    public AjaxResult list(BizCompany bizCompany) {
        LambdaQueryWrapper<BizCompany> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        return success(bizCompanyService.list(lambdaQueryWrapper));
    }

    /**
     * 分页查询项目信息列表
     * @param bizCompany
     * @return
     */
    @GetMapping("/page")
    public TableDataInfo page(BizCompany bizCompany) {
        return getDataTable(bizCompanyService.pageList(bizCompany, startPage()));
    }

    /**
     * 导出项目信息列表
     */
    @PreAuthorize("@ss.hasPermi('crane:company:export')")
    @Log(title = "项目信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCompany bizCompany) {
        LambdaQueryWrapper<BizCompany> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        List<BizCompany> list = bizCompanyService.list(lambdaQueryWrapper);
        ExcelUtil<BizCompany> util = new ExcelUtil<BizCompany>(BizCompany.class);
        util.exportExcel(response, list, "项目信息数据");
    }

    /**
     * 获取项目信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('crane:company:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(bizCompanyService.getById(id));
    }

    /**
     * 新增项目信息
     */
    @PreAuthorize("@ss.hasPermi('crane:company:add')")
    @Log(title = "项目信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCompany bizCompany) {
        return toAjax(bizCompanyService.save(bizCompany));
    }

    /**
     * 修改项目信息
     */
//    @PreAuthorize("@ss.hasPermi('crane:company:edit')")
    @Log(title = "项目信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCompany bizCompany) {
        return toAjax(bizCompanyService.updateById(bizCompany));
    }

    /**
     * 删除项目信息
     */
    @PreAuthorize("@ss.hasPermi('crane:company:remove')")
    @Log(title = "项目信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids) {
        return toAjax(bizCompanyService.removeBatchByIds(ids));
    }
}
